/**
 * Report – Detail report of programme plan (B1)
 */
package com.lightsaber.trade.cloth.web.reporting;

import java.util.ArrayList;
import java.util.List;

import org.apache.struts2.convention.annotation.Namespace;
import org.apache.struts2.convention.annotation.ParentPackage;
import org.apache.struts2.convention.annotation.Result;
import org.apache.struts2.convention.annotation.Results;
import org.springframework.beans.factory.annotation.Autowired;

import com.lightsaber.trade.cloth.entity.category.Category;
import com.lightsaber.trade.cloth.service.category.CategoryService;
import com.lightsaber.trade.cloth.service.param.ParamObject;
import com.lightsaber.trade.cloth.service.param.ParamService;
import com.lightsaber.trade.cloth.service.reporting.ReportingParamService;
import com.lightsaber.trade.cloth.service.reporting.bean.B1ReportsBean;

@Namespace("/reporting")
@ParentPackage("jasperreports-default")
@Results({
        @Result(location = "/report/report.jasper", name = "excelReports", type = "jasper", params = {
                "dataSource", "b1List", "format", "XLS", "documentName", "b1" }),
        @Result(location = "/report/report.jasper", name = "pdfReports", type = "jasper", params = {
                "dataSource", "b1List", "format", "PDF", "documentName", "b1",
                "contentDisposition", "attachment" }) })
public class B1Action extends ReportingBaseAction {

    @Autowired
    private ParamService paramService;

    /* temp service* */
    @Autowired
    private ReportingParamService reportingParamService;

    @Autowired
    private CategoryService categoryService;
    private List<Category> planningExerciseList;

    private List<B1ReportsBean> b1List = new ArrayList<B1ReportsBean>();

    private List<ParamObject> campusList;
    // private List<ParamObject> planNameList;
    // private List<ParamObject> archiveImageList;

    // private List<ParamObject> offeringUnitList;
    // private List<ParamObject> operatingUnitList;
    //
    // private List<ParamObject> studyModeList;
    // private List<ParamObject> disciplineList;
    // private List<ParamObject> fundingModeList;
    // private List<ParamObject> levelOfStudyList;
    // private List<ParamObject> programmeTypeList;
    // private List<ParamObject> programmeBoardList;
    // private List<ParamObject> adwardList;

    private B1ReportsBean b1ReportsBean;

    private String planningExercise;
    private String planName;
    private String archiveImage;
    private List<String> memberInstitutionList;
    private List<String> offeringUnitList;
    private List<String> operatingUnitList;
    private List<String> disciplineList;
    private List<String> studyModeList;
    private List<String> fundingModeList;
    private List<String> levelOfStudyList;
    private List<String> programmeTypeList;
    private List<String> programmeBoardList;
    private List<String> adwardList;
    private List<String> showDetailList;
    private boolean showCurriculumHour;
    private boolean showProjectedEnrolmentFigure;
    private String mainStream;
    private List<String> reportSummaryList;

    private List<String> campus;

    /**
     * 
     */
    private static final long serialVersionUID = 1L;

    @Override
    public String execute() throws Exception {
        planningExerciseList = categoryService.findMasterTreeList();

        // studyModeList = paramService.getStudyModeList();
        //
        // /*added*/
        campusList = reportingParamService.getCampusList();
        //
        // /*added end*/
        // disciplineList = paramService.getDisciplineList();
        // fundingModeList = paramService.getFundingModeList();
        // levelOfStudyList = paramService.getLevelOfStudyList();
        // programmeTypeList = paramService.getProgrammeTypeList();
        // programmeBoardList = paramService.getProgammeBoardList();
        // adwardList = paramService.getAwardList();
        //

        return SUCCESS;
    }

    public String getExcelReport() {

        b1List.clear();

        b1ReportsBean = new B1ReportsBean();
        b1ReportsBean.setAdwardList(convertListToString(adwardList));
        b1ReportsBean.setArchiveImage(archiveImage);
        b1ReportsBean.setCampusList(convertListToString(campus));
        b1ReportsBean.setDisciplineList(convertListToString(disciplineList));
        b1ReportsBean.setFundingModeList(convertListToString(fundingModeList));
        b1ReportsBean.setLevelOfStudyList(convertListToString(levelOfStudyList));
        b1ReportsBean.setMainStream(mainStream);
        b1ReportsBean.setMemberInstitutionList(convertListToString(memberInstitutionList));
        b1ReportsBean.setOfferingUnitList(convertListToString(offeringUnitList));
        b1ReportsBean.setOperatingUnitList(convertListToString(operatingUnitList));
        b1ReportsBean.setPlanName(planName);
        b1ReportsBean.setPlanningExercise(planningExercise);
        b1ReportsBean.setProgrammeBoardList(convertListToString(programmeBoardList));
        b1ReportsBean.setProgrammeTypeList(convertListToString(programmeTypeList));
        b1ReportsBean.setReportSummaryList(convertListToString(reportSummaryList));
        b1ReportsBean.setShowCurriculumHour(showCurriculumHour);
        b1ReportsBean.setShowDetailList(convertListToString(showDetailList));
        b1ReportsBean.setShowProjectedEnrolmentFigure(showProjectedEnrolmentFigure);
        b1ReportsBean.setStudyModeList(convertListToString(studyModeList));

        b1List.add(b1ReportsBean);

        return "excelReports";

    }

    public String getPDFReport() {
        b1List.clear();

        b1ReportsBean = new B1ReportsBean();
        b1ReportsBean.setAdwardList(convertListToString(adwardList));
        b1ReportsBean.setArchiveImage(archiveImage);
        // b1ReportsBean.setCampusList(convertListToString(campusList));
        b1ReportsBean.setDisciplineList(convertListToString(disciplineList));
        b1ReportsBean.setFundingModeList(convertListToString(fundingModeList));
        b1ReportsBean.setLevelOfStudyList(convertListToString(levelOfStudyList));
        b1ReportsBean.setMainStream(mainStream);
        b1ReportsBean.setMemberInstitutionList(convertListToString(memberInstitutionList));
        b1ReportsBean.setOfferingUnitList(convertListToString(offeringUnitList));
        b1ReportsBean.setOperatingUnitList(convertListToString(operatingUnitList));
        b1ReportsBean.setPlanName(planName);
        b1ReportsBean.setPlanningExercise(planningExercise);
        b1ReportsBean.setProgrammeBoardList(convertListToString(programmeBoardList));
        b1ReportsBean.setProgrammeTypeList(convertListToString(programmeTypeList));
        b1ReportsBean.setReportSummaryList(convertListToString(reportSummaryList));
        b1ReportsBean.setShowCurriculumHour(showCurriculumHour);
        b1ReportsBean.setShowDetailList(convertListToString(showDetailList));
        b1ReportsBean.setShowProjectedEnrolmentFigure(showProjectedEnrolmentFigure);
        b1ReportsBean.setStudyModeList(convertListToString(studyModeList));

        b1List.add(b1ReportsBean);

        b1List.add(b1ReportsBean);

        return "pdfReports";

    }

    private String convertListToString(final List<String> list) {

        if (list == null) {
            return null;
        }
        StringBuffer sb = new StringBuffer();
        for (String s : list) {
            sb.append(s);
            sb.append("\n");
        }

        return sb.toString();

    }

    public void setParamService(final ParamService paramService) {
        this.paramService = paramService;
    }

    public ParamService getParamService() {
        return paramService;
    }

    public ReportingParamService getReportingParamService() {
        return reportingParamService;
    }

    public void setReportingParamService(final ReportingParamService reportingParamService) {
        this.reportingParamService = reportingParamService;
    }

    public List<Category> getPlanningExerciseList() {
        return planningExerciseList;
    }

    public void setPlanningExerciseList(final List<Category> planningExerciseList) {
        this.planningExerciseList = planningExerciseList;
    }

    public List<ParamObject> getCampusList() {
        return campusList;
    }

    public void setCampusList(final List<ParamObject> campusList) {
        this.campusList = campusList;
    }

    public List<B1ReportsBean> getB1List() {
        return b1List;
    }

    public void setB1List(final List<B1ReportsBean> b1List) {
        this.b1List = b1List;
    }

    public B1ReportsBean getB1ReportsBean() {
        return b1ReportsBean;
    }

    public void setB1ReportsBean(final B1ReportsBean b1ReportsBean) {
        this.b1ReportsBean = b1ReportsBean;
    }

    public CategoryService getCategoryService() {
        return categoryService;
    }

    public void setCategoryService(final CategoryService categoryService) {
        this.categoryService = categoryService;
    }

    public String getPlanningExercise() {
        return planningExercise;
    }

    public void setPlanningExercise(final String planningExercise) {
        this.planningExercise = planningExercise;
    }

    public String getPlanName() {
        return planName;
    }

    public void setPlanName(final String planName) {
        this.planName = planName;
    }

    public String getArchiveImage() {
        return archiveImage;
    }

    public void setArchiveImage(final String archiveImage) {
        this.archiveImage = archiveImage;
    }

    public List<String> getMemberInstitutionList() {
        return memberInstitutionList;
    }

    public void setMemberInstitutionList(final List<String> memberInstitutionList) {
        this.memberInstitutionList = memberInstitutionList;
    }

    public List<String> getOfferingUnitList() {
        return offeringUnitList;
    }

    public void setOfferingUnitList(final List<String> offeringUnitList) {
        this.offeringUnitList = offeringUnitList;
    }

    public List<String> getOperatingUnitList() {
        return operatingUnitList;
    }

    public void setOperatingUnitList(final List<String> operatingUnitList) {
        this.operatingUnitList = operatingUnitList;
    }

    public List<String> getDisciplineList() {
        return disciplineList;
    }

    public void setDisciplineList(final List<String> disciplineList) {
        this.disciplineList = disciplineList;
    }

    public List<String> getStudyModeList() {
        return studyModeList;
    }

    public void setStudyModeList(final List<String> studyModeList) {
        this.studyModeList = studyModeList;
    }

    public List<String> getFundingModeList() {
        return fundingModeList;
    }

    public void setFundingModeList(final List<String> fundingModeList) {
        this.fundingModeList = fundingModeList;
    }

    public List<String> getLevelOfStudyList() {
        return levelOfStudyList;
    }

    public void setLevelOfStudyList(final List<String> levelOfStudyList) {
        this.levelOfStudyList = levelOfStudyList;
    }

    public List<String> getProgrammeTypeList() {
        return programmeTypeList;
    }

    public void setProgrammeTypeList(final List<String> programmeTypeList) {
        this.programmeTypeList = programmeTypeList;
    }

    public List<String> getProgrammeBoardList() {
        return programmeBoardList;
    }

    public void setProgrammeBoardList(final List<String> programmeBoardList) {
        this.programmeBoardList = programmeBoardList;
    }

    public List<String> getAdwardList() {
        return adwardList;
    }

    public void setAdwardList(final List<String> adwardList) {
        this.adwardList = adwardList;
    }

    public List<String> getShowDetailList() {
        return showDetailList;
    }

    public void setShowDetailList(final List<String> showDetailList) {
        this.showDetailList = showDetailList;
    }

    public boolean isShowCurriculumHour() {
        return showCurriculumHour;
    }

    public void setShowCurriculumHour(final boolean showCurriculumHour) {
        this.showCurriculumHour = showCurriculumHour;
    }

    public boolean isShowProjectedEnrolmentFigure() {
        return showProjectedEnrolmentFigure;
    }

    public void setShowProjectedEnrolmentFigure(final boolean showProjectedEnrolmentFigure) {
        this.showProjectedEnrolmentFigure = showProjectedEnrolmentFigure;
    }

    public String getMainStream() {
        return mainStream;
    }

    public void setMainStream(final String mainStream) {
        this.mainStream = mainStream;
    }

    public List<String> getReportSummaryList() {
        return reportSummaryList;
    }

    public void setReportSummaryList(final List<String> reportSummaryList) {
        this.reportSummaryList = reportSummaryList;
    }

}
